package com.zlk.algorithm.algorithm.sort.heap;

import java.util.ArrayList;
import java.util.List;
import java.util.PriorityQueue;

/**
 * @program: algorithm
 * @ClassName Test
 * @description:
 * @author: slfang
 * @create: 2024-04-29 19:09
 * @Version 1.0
 **/
public class Test {

    public static void main(String[] args) {
        List<Person> people = new ArrayList<>();
        people.add(new Person("张三",2,1));
        people.add(new Person("李四",2,2));
        people.add(new Person("张三",3,2));
        PriorityQueue<Person> priorityQueue = new PriorityQueue<>((a,b)->{
            return a.level==b.level?b.age-a.age:b.level-a.level;
        });

        for (int i = 0; i < people.size(); i++) {
            priorityQueue.add(people.get(i));
        }

        while (!priorityQueue.isEmpty()){
            System.out.println(priorityQueue.poll());

        }
    }
}

class Person{
    String name;
    int age;
    int level;

    public Person(String name, int age,int level) {
        this.name = name;
        this.age = age;
        this.level = level;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", level=" + level +
                '}';
    }
}
